{include file="public/header" /}
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.course_list}</h3>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

    <form id="goods_class_form" enctype="multipart/form-data" method="post" action='course_son_add'>
        <table class="ds-default-table">
            <tbody>
                <tr class="noborder">
                    <td colspan="2" class="required"><label class="validation" >{$Think.lang.ds_son_course}:</label>
<input style="margin-left: 57px;" type="text" value="" name="title" id="title" maxlength="20" class="txt">
                    </td>
                </tr>
              <!--   <tr class="noborder">
                    <td class="vatop rowform"><input type="text" value="" name="title" id="title" maxlength="20" class="txt"></td>
                </tr> -->
                 <tr class="noborder">
                    <td colspan="2" class="required"><label class="validation" >{$Think.lang.course_sort}:</label>
                    <input style="margin-left: 96px;" type="text" value="" name="x_id" id="x_id" maxlength="20" class="txt">
                  </td>
                </tr>
                <!-- <tr class="noborder">
                    <td class="vatop rowform"><input type="text" value="" name="x_id" id="x_id" maxlength="20" class="txt"></td>
                </tr> -->
                <tr class="noborder">
                    <td colspan="2" class="required"><label class="validation" >{$Think.lang.course_status}:</label>
                      <div style="margin-top: -13px;margin-left: 146px;" class="onoff">
                        <label for="site_state1" class="cb-enable selected" >启用</label>
                        <label for="site_state0" class="cb-disable">停用</label>
                        <input id="site_state1" name="status" value="1" type="radio" checked="checked">
                        <input id="site_state0" name="status" value="0" type="radio">
                    </div>

                    </td>
                </tr>
                <!-- <tr class="noborder">
                    <td class="vatop rowform">
                      <div class="onoff">
                        <label for="site_state1" class="cb-enable selected" >启用</label>
                        <label for="site_state0" class="cb-disable">停用</label>
                        <input id="site_state1" name="status" value="1" type="radio" checked="checked">
                        <input id="site_state0" name="status" value="0" type="radio">
                    </div>
                          </td>
                </tr> -->
                <tr>
                    <td colspan="2" class="required"><label class="validation" >类型</label>
                        <input style="margin-left: 94px;" id="qu1" name="qu" value="1" type="radio" checked="checked">视频教程
                        <input id="qu2" name="qu" value="2" type="radio">图文详情
                    </td>
                </tr>
<!--                 <tr class="noborder">
                <tr class="noborder">
                    <td class="vatop rowform">
                        <input id="qu1" name="qu" value="1" type="radio" checked="checked">视频教程
                        <input id="qu2" name="qu" value="2" type="radio">图文详情
                    </td>
                </tr>
                </tr> -->

                <tr class="noborder" id= "son_hide">
                     <td colspan="2" class="required"><label for="pic">{$Think.lang.ds_son_video}:</label>
                         <input type="hidden" name="pic" id="imgss">
                         <input style="margin-left: 76px;" name="video" type="file" id="pic" size="30" hidefocus="true" ds_type="change_pic">
                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                         <span>支持后缀名为：*.avi *.mov *.wmv *.mp4 的文件</span>
                     </td>
                </tr>
<!--                 <tr class="noborder"  >
                     <td class="vatop rowform">
                         <input type="hidden" name="pic" id="imgss">
                         <input name="video" type="file" id="pic" size="30" hidefocus="true" ds_type="change_pic">
                     </br>
                         </br>
                         <span>支持后缀名为：*.avi *.mov *.wmv *.mp4 的文件</span>
                     </td>
                </tr> -->
                <tr class="noborder"  id="article_content_show">
                     <td colspan="2" class="required"><label  >{$Think.lang.ds_son_tuwen}:</label>
<td class='wenben'>
                      <!-- <div id="panel-1" class="ui-tabs-panel">{:build_editor(["name"=>"goods_body"])}<textarea name="content" id="goods_body"></textarea><p id="des_demo"></p>-->
                <tr class="noborder" id="article_content_show">
                    {:build_editor(['name'=>'article_content'])}
                    <td class="vatop rowform" colspan="2"><textarea name="content" id="article_content" style="width:100%;"></textarea></td>
                </tr>
                <tr id="article_content_show">
                    <td class="required">上传图片:</td>
                    <td id="divComUploadContainer"><input type="file" multiple="multiple" id="fileupload" name="fileupload" /></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr id="article_content_show">
                    <td class="required">已上传图片:</td>
                    <td><div class="tdare">
                        <table width="600px" cellspacing="0" class="dataTable">
                            <tbody id="thumbnails">
                            {notempty name="file_upload"}
                            {foreach name="file_upload" item="v"}
                            <tr id="{$v.upload_id}" class="tatr2">
                                <input type="hidden" name="file_id[]" value="{$v.upload_id}" />
                                <td><img width="40px" height="40px" src="{$Think.UPLOAD_SITE_URL}/{$Think.ATTACH_ARTICLE}/{$v.file_name}" /></td>
                                <td>{$v.file_name}</td>
                                <td><a href="javascript:insert_editor('{$Think.UPLOAD_SITE_URL}/{$Think.ATTACH_ARTICLE}/{$v.file_name}');">{$Think.lang.article_index_insert}</a> | <a href="javascript:del_file_upload('{$v.upload_id}');">{$Think.lang.ds_del}</a></td>
                            </tr>
                            {/foreach}
                            {/notempty}
                            </tbody>
                        </table>
                    </div>
                  </td>

                   </td>

                     </td>
                </tr>
                
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2">
                      <input class="btn" type="hidden" value="{$course_id}" name='course_id'/>
                      <input class="btn" type="button" value="{$Think.lang.ds_submit}" id='aa'/></td>
                </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>


<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-file-upload/jquery.fileupload.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('tr[id="article_content_show"]').hide(); 
    });
    $(function() {
         $('input[name="qu"]').click(function() {
            if ($(this).val() == 1) {
                $('tr[id="article_content_show"]').hide(); 
                $('tr[id="son_hide"]').show();  
            } else {
                $('tr[id="article_content_show"]').show(); 
                $('tr[id="son_hide"]').hide();   
            }
         });
    });
    $(function() {
        $("#_pic").change(function () {
            $("#article_pic").val($(this).val());
        });

        // 图片上传
        $('#fileupload').each(function(){
            $(this).fileupload({
                dataType: 'json',
                url: "{:url('Article/article_pic_upload',['item_id'=>1])}",
                done: function (e,data) {
                    if(data != 'error'){
                        add_uploadedfile(data.result);
                    }
                }
            });
        });

        
        
    });
    function add_uploadedfile(file_data)
    {
        var newImg = '<tr id="' + file_data.file_id + '" class="tatr2"><input type="hidden" name="file_id[]" value="' + file_data.file_id + '" /><td><img width="40px" height="40px" src="' + file_data.file_path + '" /></td><td>' + file_data.file_name + '</td><td><a href="javascript:insert_editor(\'' + file_data.file_path + '\');">导入编辑器</a> | <a href="javascript:del_file_upload(' + file_data.file_id + ');">{$Think.lang.ds_del}</a></td></tr>';
        $('#thumbnails').prepend(newImg);
    }
    function insert_editor(file_path){
        ue.execCommand('insertimage', {src:file_path});
    }
    function del_file_upload(file_id)
    {
        layer.confirm('{$Think.lang.ds_ensure_del}', {
            btn: ['{$Think.lang.ds_ok}', '{$Think.lang.ds_cancel}'],
            title: false,
        }, function () {
            $.getJSON("{:url('Article/ajax')}",{branch:'del_file_upload',file_id: + file_id}, function(result){
                if(result){
                    $('#' + file_id).remove();
                    layer.msg('{$Think.lang.ds_common_del_succ}');
                }else{
                    layer.alert('{$Think.lang.article_index_del_fail}');
                }
            });
        });
    }
</script>

<script>
//按钮先执行验证再提交表单
              $(function() {
                  //视频上传
                  $(document).on('change','#pic',function() {
                      var files = document.getElementById('pic').files[0];
                      var formData = new FormData();
                      formData.append('file',files);
                      layer.msg('正在上传，请稍等');
                      $.ajax({
                          //请求方式
                          type : "POST",
                          //请求地址
                          url : "{:url('Course/ajax_videos')}",
                          data : formData,
                          cache:false,  //默认是true，但是一般不做缓存
                          processData:false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                          contentType:false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                          //请求成功
                          success : function(result) {
                           //   alert(result);return false;
                              if(result.err==0){
                                  layer.msg(result.msg);
                                  $('#imgss').val(result.files_name);
                              }else{
                                  $('#pic').val('');
                                  alert('文件格式错误,请重新上传');return false;
                              }
                          },
                          //请求失败，包含具体的错误信息
                          error : function(e){
                              console.log(e.status);
                              console.log(e.responseText);
                          }
                      });

                  });


                  $('#type_div').perfectScrollbar();
                  $("#pic").change(function() {
                      $("#textfield1").val($(this).val());
                  });
                  $('input[type="radio"][name="cat_id"]').click(function() {
                      if ($(this).val() == '0') {
                          $('#t_name').val('');
                      } else {
                          $('#t_name').val($(this).next('span').html());
                      }
                  });
                  // 所属分类
                  $(document).off('change',"#gc_parent_id").on("change","#gc_parent_id", function() {
                      type_scroll($(this));
                  });
                  // 类型搜索
                  $(document).off('change',"#gcategory > select").on("change","#gcategory > select", function() {
                      type_scroll($(this));
                  });
                   $('.btn').click(function(){
                      var title = $("#title").val();
                      var x_id = $("#x_id").val();
                       // 判断
                      if(title.length == ''){
                          alert('请输入教程标题');
                          return false;
                      }
                       if(x_id.length == ''){
                          alert('请输入教程序号');
                          return false;
                      }

                       var url = $('form').attr('action');
                       $.ajax({
                           type: "POST",
                           url:url,
                           data:$('#goods_class_form').serialize(),// 你的formid

                           error: function(request) {
                               alert("Connection error");
                           },
                           success: function(data) {
                             //  alert(data);return false;
                               if(data.code==0){
                                   layer.msg(data.msg);
                                   location.href=data.url;return false;
                               }else{
                                   layer.msg(data.msg);
                                   location.href=data.url;return false;

                               }
                           }
                       }); return false;



                   });
                });

              var typeScroll = 0;
              function type_scroll(o) {
                  var id = o.val();
                  if (!$('#type_dt_' + id).is('dt')) {
                      return false;
                  }
                  $('#type_div').scrollTop(-typeScroll);
                  var sp_top = $('#type_dt_' + id).offset().top;
                  var div_top = $('#type_div').offset().top;
                  $('#type_div').scrollTop(sp_top - div_top);
                  typeScroll = sp_top - div_top;
              }
              gcategoryInit('gcategory');
</script>


